package top.lshaci.learning.springboot.jpa.service;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import top.lshaci.learning.springboot.jpa.entity.Person;
import top.lshaci.learning.springboot.jpa.repository.PersonRepository;

/**
 * PersonService
 *
 * @author liangxu
 */
@Service
public class PersonService {

    @Autowired
    PersonRepository personRepository;

    @Transactional(rollbackFor = Exception.class)
    public void save() {
        try {
            Person person = new Person();
            person.setName("十七");
            person.setAge(12);
            person.setRoleId(1L);
            personRepository.save(person);
            int i = 1 / 0;
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
